﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
/*using System.IO;*/
using System.Linq;
/*using System.Net;*/
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
//文件夹using
/*using System.Diagnostics;*/

namespace Disk
{
  
    public partial class firstpage : Form
    {
        bool flag = true;
        public static login login = new login();
        public static changecode changecode = new changecode();
        public firstpage()
        {
            InitializeComponent();
        }
        private void firstpage_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag)
            {
                if (MessageBox.Show("要退出程序吗？", "退出程序", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    //取消订阅事件
                    this.FormClosing -= firstpage_FormClosing;
                    Application.Exit();
                }
                else
                {
                    e.Cancel = true;
                }
            }
            
        }
        private void firstpage_Load(object sender, EventArgs e)
        {
        }
        //点击图片在面板中显示图片窗体
        private void button3_Click(object sender, EventArgs e)
        {
            panel2.Controls.Clear();
            dataGridView1.Dock = DockStyle.Fill;
            panel2.Controls.Add(dataGridView1);
            dataGridView1.Show();
            int Allfile = 2;//图片
            Upload.Show(Allfile);
        }
        //点击视频在面板中显示视频窗体
        private void button5_Click(object sender, EventArgs e)
        {
            panel2.Controls.Clear();
            dataGridView1.Dock = DockStyle.Fill;
            panel2.Controls.Add(dataGridView1);
            dataGridView1.Show();
            int Allfile = 3;//视频
            Upload.Show(Allfile);
        }
        //点击音乐在面板中显示音乐窗体
        private void button6_Click(object sender, EventArgs e)
        {
            panel2.Controls.Clear();
            dataGridView1.Dock = DockStyle.Fill;
            panel2.Controls.Add(dataGridView1);
            dataGridView1.Show();
            int Allfile = 4;//音频
            Upload.Show(Allfile);
        }
        //点击文件在面板中显示文件窗体
        private void button7_Click(object sender, EventArgs e)
        {
            panel2.Controls.Clear();
            dataGridView1.Dock = DockStyle.Fill;
            panel2.Controls.Add(dataGridView1);
            dataGridView1.Show();
            int Allfile = 5;//文档
            Upload.Show(Allfile);
        }
        //点击所有文档在面板中显示所有文档窗体
        private void button8_Click(object sender, EventArgs e)
        {
            panel2.Controls.Clear();
            dataGridView1.Dock = DockStyle.Fill;
            panel2.Controls.Add(dataGridView1);
            dataGridView1.Show();
            int Allfile = 1;//所有文件
            Upload.Show(Allfile);
        }

        //上传点击事件
        private void pictureBox6_Click(object sender, EventArgs e)
        {
            //初始化一个OpenFileDialog类
            OpenFileDialog fileDialog = new OpenFileDialog();

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                //获取用户选择文件的后缀名
                string extension = Path.GetExtension(fileDialog.FileName);
                //声明允许的后缀名
              
                    FileInfo fileInfo = new FileInfo(fileDialog.FileName);
                        int num =Upload.AAD(fileDialog.FileName);
                        if (num == 1)
                        {
                            MessageBox.Show("上传失败");
                }
                        if (num == 2)
                        {
                            MessageBox.Show("上传成功");
                }
            }
        }
        //下载点击事件
        private void pictureBox5_Click(object sender, EventArgs e)
        {
            int i = this.dataGridView1.CurrentRow.Index;
                string Filename = dataGridView1.Rows[i].Cells["Filename"].Value.ToString();

                bool result = FileDown.Down(Filename);
                if (result == true)
                {
                    MessageBox.Show("下载成功");
                }
                else
                {
                    MessageBox.Show("下载失败");
                }
        }
        //分享点击事件
        private void pictureBox7_Click(object sender, EventArgs e)
        {
            //选中的文件生成对应的链接或提取码 在messagebox中显示给用户，内容可复制

        }
        //删除点击事件
        private void pictureBox8_Click(object sender, EventArgs e)
        {
            //选中的文件删除后在文件列表更新内容并提示删除成功
        }
        //全选
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if ((Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value) == false))
                {
                    dataGridView1.Rows[i].Cells[0].Value = "True";
                }
                else
                    continue;
            }
        }
        //取消全选
        private void 取消全选ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if ((Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value) == true))
                {
                    dataGridView1.Rows[i].Cells[0].Value = "False";
                }
                else
                    continue;
            }
        }
        //修改密码单击事件
        private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flag = false;
            //显示修改密码窗体
            new Thread(()=> {
                Application.Run(changecode);
            }).Start();
            this.Close();
        }
        //注销账户单击事件
        private void 注销账户ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("是否要注销账户？\n（请确保文件已清空，再进行操作）", "注销提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (result == DialogResult.OK)
            {
                //清空用户所有信息，或者标识为不能登录状态
                //注销成功回到登录界面
                MessageBox.Show("注销成功，回到登陆界面", "注销提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                flag = false;
                new Thread(() => {
                    Application.Run(login);
                }).Start();
                this.Close();
            }
        }
        //搜索文件点击事件
        private void searchBox10_Click(object sender, EventArgs e)
        {

        }
        //重命名点击事件
        private void pictureBox9_Click(object sender, EventArgs e)
        {

        }
    }
}
